<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户列表</title>


    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>
    <link href="../../resource/hotui/css/font-awesome.min.css" rel="stylesheet"
          th:href="@{/resource/hotui/css/font-awesome.min.css}">
    <!-- Morris -->
    <link href="../../resource/hotui/css/plugins/morris/morris-0.4.3.min.css"
          rel="stylesheet" th:href="@{/resource/hotui/css/plugins/morris/morris-0.4.3.min.css}">
    <link href="../../resource/css/animate.min.css" rel="stylesheet" th:href="@{/resource/css/animate.min.css}"/>
    <link href="../../resource/hotui/css/style.min-1.0.8.css" rel="stylesheet"
          th:href="@{/resource/hotui/css/style.min-1.0.8.css}">
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>

    <!--    <link href="../../resource/css/style-diy.css?v=4.0.0" rel="stylesheet"-->
    <!--          th:href="@{/resource/css/style-diy.css?v=4.0.0}"/>-->
    <link href="../../resource/hotui/js/plugins/datetimepick/css/daterangepicker.css"
          th:href="@{/resource/hotui/js/plugins/datetimepick/css/daterangepicker.css}" rel="stylesheet"/>
    <style>
        .modal-content-tag {
            display: none;
        }
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!--search-->
    <form role="form" id="searchForm" class="search-panel" method="get" th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <input type="hidden" th:value="${pageIndex}" name="pageIndex"/>
                            <input name="type" th:value="${type}" type="hidden"/>
                            <div class="form-inline">
                                <div class="form-group m-r-sm">
                                    <label class=" control-label" for="keyword">关键字：</label>
                                    <input type="text" class="form-control input-sm mb10" id="keyword"
                                           th:value="*{keyword}"
                                           name="keyword" placeholder="关键字" style="width: 156px;"/>
                                </div>
                                <div class="form-group m-r-sm">
                                    <label class=" control-label" for="createTimePick">创建时间：</label>
                                    <input readonly type="text" class="form-control input-sm mb10 data-range-pick"
                                           id="createTimePick" start-element="#beginTime"
                                           end-element="#endTime" placeholder="开始时间-结束时间" style="width: 377px;"/>
                                    <input type="hidden" th:value="*{beginTime}" id="beginTime" name="beginTime"/>
                                    <input type="hidden" th:value="*{endTime}" id="endTime" name="endTime"/>
                                </div>
                                <div class="form-group m-r-sm">
                                    <button type="button" onclick="listHandler.search(1)"
                                            class="btn btn-primary btn-sm m-b-none searchBtn">筛选
                                    </button>
                                    <button type="button" onclick="listHandler.searchAll()"
                                            class="btn btn-primary btn-sm m-b-none">显示全部
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->


    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li class="active" th:class="${condition.status==-1?'active':''}">
                            <a th:href="@{/user/list}" href="#tab-2">全部</a>
                        </li>
                        <li th:class="${condition.status==1?'active':''}">
                            <a th:href="@{/user/list(status=1)}">激活</a>
                        </li>
                        <li th:class="${condition.status==0?'active':''}">
                            <a th:href="@{/user/list(status=0)}">禁用</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body table-responsive">

                                <table class="table table-bordered table-hover table-center"
                                       th:each="user,stat:${list}">
                                    <thead>
                                    <tr>
                                        <th colspan="12"
                                            style="color: #636e7b; padding-bottom: 0px; text-align: left;">
                                            用户名： <span th:text="${user.mobile}">--</span>
                                            昵称： <span style="margin-right: 10px;display: inline-block"
                                                      th:text="${user.nickName}"></span>
                                            状态： <span class="color-primary"
                                                      th:text="${user.enabled?'激活':'冻结'}"></span>
                                            <p style="float: right;">
                                                <span>注册时间</span>：<span
                                                    th:text="${#temporals.format(user.createTime,'yyyy-MM-dd HH:mm:ss')}"></span>
                                            </p>
                                        </th>
                                    </tr>
                                    </thead>
                                    <tr>
                                        <td style="width: 40px">头像</td>
                                        <td style="width: 60px">手机</td>
                                        <td>昵称</td>
                                        <td style="width: 100px">余额</td>
                                        <td style="width: 100px">等级</td>
                                        <td>推荐人</td>
                                        <td style="width: 60px">状态</td>
                                        <td style="width: 200px">操作</td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <img alt="" style="border-radius: 10px;" height="40" th:src="${user.avatar}"
                                                 width="40"/>
                                        </td>
                                        <td>
                                            <span th:text="${user.mobile}">--</span>
                                        </td>
                                        <td>
                                            <span th:text="${user.nickName}">--</span>
                                        </td>
                                        <td>
                                            ￥<span th:text="${user.balance}">0</span>
                                        </td>
                                        <td>
                                            <span th:text="${user.userLevel.desc}">0</span>
                                        </td>
                                        <td>
                                            <th:block th:if="${user.guider!=null}">
                                                <span th:text="${user.guider.mobile}"></span>
                                                <br>
                                                <span th:text="${user.guider.nickName}"></span>
                                            </th:block>
                                        </td>
                                        <td th:text="${user.enabled?'激活':'冻结'}">
                                            <!--                                            -->
                                            <!--                                            <input th:onchange="|listHandler.setDisabled(this,${user.userId})|"-->
                                            <!--                                                   onchange="listHandler.setDisabled(this,1)" type="checkbox"-->
                                            <!--                                                   class="js-switch" th:checked="${user.enabled}" checked/>-->
                                        </td>
                                        <td>
                                            <button th:onclick="listHandler.detail([[${user.userId}]],[[${user.mobile}]])"
                                                    type="button"
                                                    class="btn btn-info btn-xs m-b-none">详情
                                            </button>
                                            <button class="btn btn-info btn-xs m-b-none" style="display: none"
                                                    onclick="listHandler.changeWallet(1)"
                                                    th:onclick="|listHandler.changeWallet(${user.userId})|"
                                                    type="button">修改余额
                                            </button>
                                        </td>
                                    </tr>
                                </table>
                                <p style="float: left; margin: 20px 0;">
                                    共<span th:text="${totalRecords}"></span>条记录，当前第<span
                                        th:text="${pageIndex}"></span>/<span
                                        th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                </p>
                                <ul style="float: right;" class="pagination pagination-split">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>


<div id="wallet_modify_modal" class="modal-content-tag">
    <form id="wallet_form">
        <input name="userId" type="hidden"/>
        <div class="form-horizontal" style="width: 479px;">
            <div class="form-group form-inline">
                <label class="col-sm-3 control-label">*调整余额：</label>
                <div class="col-sm-9">
                    <input class="form-control input-sm input-s only-float" id="wallet_amount" name="amount"
                           placeholder="调整量" required type="text"/>
                    <br/>
                    <p class="form-control-static color-notice">减少请输入负数</p>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <label class="col-sm-3 control-label">*备注：</label>
                <div class="col-sm-9">
                    <textarea class="form-control" id="wallet_remark" name="remark" placeholder="备注"
                              rows="5" style="height: 100px;width: 300px;"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>
<!--基础框架js-->
<script src="../../resource/js/jquery.min.js?v=2.1.4" th:src="@{/resource/js/jquery.min.js?v=2.1.4}"></script>
<script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js?v=3.3.5}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js}"
></script>

<script src="../../resource/lib/moment.min.js" th:src="@{/resource/lib/moment.min.js}"></script>
<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>

<script src="../resource/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="../resource/lib/jquery-validation/dist/messages_cn.js"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-validate.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-validate.js}"></script>


<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  1;
    const pageUri = /*[[@{/user/list}]]*/  "";
    const detailUri = /*[[@{/user/detail}]]*/  "";
    const modifyBalanceUri = /*[[@{/user/modifyBalance}]]*/  "";

</script>
<script>

    let walletModal = $('#wallet_modify_modal').modal('调整余额', function () {
        $('#wallet_form').submit();
    });


    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            listHandler.search(p);
        });
        $(document).keyup(function (event) {
            if (event.keyCode === 13) {
                $(".searchBtn").trigger("click");
            }
        });
    });
    let listHandler = {
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri;
        },
        detail: function (dataId) {
            hot.newTab(detailUri + "?userId=" + dataId, "用户详情");
        },
        setDisabled: function (obj, userId) {
            let currentStatus = obj.checked;
            hot.ajax(userApiBase + userUriConstant.setDisabled, {
                userId: userId,
                disabled: !currentStatus
            }, function (apiResult) {
                if (apiResult.resultCode !== 2000) {
                    hot.tip.error("操作失败--" + apiResult.resultMsg, function () {
                        window.location.reload();
                    });
                }
            }, function () {
            }, "post");
        },
        changeWallet: function (userId) {
            walletModal.show(function () {
                let form = $('#wallet_form');
                $('[name=id]', form).val(userId);
                $('[name=amount]', form).val('');
                $('[name=remark]', form).val('');
                form.validateCallback(function () {
                    $.ajax(modifyBalanceUri, {
                        method: 'POST',
                        data: {
                            id: userId,
                            amount: $('[name=amount]', form).val(),
                            remark: $('[name=remark]', form).val()
                        },
                        success: function (apiResult) {
                            if (apiResult.resultCode === 2000) {
                                walletModal.hide(function () {
                                    hot.tip.success("调整成功", function () {
                                        $("#searchForm").submit();
                                    });
                                });
                            } else {
                                hot.tip.error("调整失败--" + apiResult.resultMsg);
                            }
                        }
                    })
                });
            });
        }

    }
</script>
</body>
</html>